<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('bars', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique()->comment('贴吧名称');
            $table->string('slug')->unique()->comment('URL友好名称');
            $table->string('avatar')->nullable()->comment('贴吧头像');
            $table->text('description')->nullable()->comment('贴吧简介');
            $table->unsignedInteger('member_count')->default(0)->comment('成员数');
            $table->unsignedInteger('post_count')->default(0)->comment('帖子数');
            $table->unsignedBigInteger('owner_id')->comment('吧主ID');
            $table->timestamps();

            $table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
            $table->index('name');
            $table->index('slug');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('bars');
    }
};
